package com.czxy.Demo17;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    public static void main(String[] args) {
        Student s1=new Student("zhangsan",18,"男");
        Student s2=new Student("lihong",22,"女");
        Student s3=new Student("wangwu",19,"男");
        Student s4=new Student("wuwu",8,"女");
        Student s5=new Student("lilin",35,"男");

        List<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        //  用来统计性别
        Map<String , Integer> sex = new HashMap<>();
        sex.put("男" , 0);
        sex.put("女" , 0);
        //  用来统计是否成年
        Map<String , Integer> age = new HashMap<>();
        age.put("成年",0);
        age.put("未成年",0);

        for (Student student : list) {
            // 如果为男性
            if (student.getSex().equals("男")){
                sex.put("男" , sex.get("男")+1);
            }
            // 如果为女性
            if (student.getSex().equals("女")){
                sex.put("女" , sex.get("女")+1);
            }
            //  如果成年
            if (student.getAge() >= 18){
                age.put("成年" , age.get("成年")+1);
            }
            //  如果未成年
            if (student.getAge() < 18){
                age.put("未成年" , age.get("未成年")+1);
            }
        }
        //  打印个数结果
        for (String s : sex.keySet()) {
            System.out.println(s + "(" + sex.get(s) + ")");
        }
        //  打印成年结果
        for (String s : age.keySet()) {
            System.out.println( s + " : " + age.get(s));
        }
    }
}
